//============================================================================================
/**
 * @file	scr_kinomi.c
 * @brief
 * @author	tamada GAME FREAK inc.
 * @date	2006.05.23
 *
 * scrcmd.cが膨れ上がってきたのできのみ関連部分を独立させた
 */
//============================================================================================

#include "common.h"
#include "script.h"
#include "scrcmd_def.h"
#include "scr_kinomi.h"

#include "fieldsys.h"

#include "system/wordset.h"
#include "savedata/record.h"

#include "bong_sys.h"
#include "bong_evt.h"

//--------------------------------------------------------------------------------------------
/**
 * ボングリ収穫アニメ
 *
 * @param	core		仮想マシン制御構造体へのポインタ
 *
 * @return	"1"
 */
//--------------------------------------------------------------------------------------------
BOOL EvCmdBonguriGetAnm( VM_MACHINE * core )
{
	u16 wk_id;
	FIELD_OBJ_PTR *fldobj;
	wk_id = VMGetU16( core );
	fldobj = GetEvScriptWorkMemberAdrs( core->fsys, ID_EVSCR_TARGET_OBJ );
	BongEvt_CallGetEvt(core->fsys, *fldobj ,GetEventWorkAdrs(core->fsys,wk_id));
	return 1;
}

//--------------------------------------------------------------------------------------------
/**
 * ボングリの実カラーナンバー取得
 *
 * @param	core		仮想マシン制御構造体へのポインタ
 *
 * @return	"0"
 */
//--------------------------------------------------------------------------------------------
BOOL EvCmdGetBongColorNo( VM_MACHINE * core )
{
	u16 wk_id;
	u16 *rc;
	FIELD_OBJ_PTR *fldobj;

	wk_id = VMGetU16( core );

	fldobj = GetEvScriptWorkMemberAdrs( core->fsys, ID_EVSCR_TARGET_OBJ );
	rc = GetEventWorkAdrs(core->fsys,wk_id);
	*rc = BongSys_GetBongColor(core->fsys, *fldobj);
	return 0;
}

/*
 *	@brief	ぼんぐりの実を取得
 */
BOOL EvCmdAddBonguri( VM_MACHINE * core )
{
	u16 *ret_wk;
	u8	color, num;
	BONGURI_SAVE* bong;

	color = VMGetWorkValue( core );
	num = VMGetWorkValue( core );
	ret_wk = VMGetWork( core );

	bong = SaveData_GetBonguriSave(core->fsys->savedata);
	if((BonguriSave_GetBonguriNum(bong,color)+num) <= BONGURI_KEEP_MAX){
		//追加
		BonguriSave_BonguriAdd(bong,color,num);
		*ret_wk = TRUE;
	}else{
		//追加失敗
		*ret_wk = FALSE;
	}
	return 0;
}
